package top.zhimingw.service.impl;

import org.springframework.stereotype.Service;
import top.zhimingw.pojo.Admin;
import top.zhimingw.redis.AdminKey;
import top.zhimingw.service.AdminService;
import top.zhimingw.service.BaseService;

/**
 * @ClassName AdminServiceImpl
 * Description (Admin)表服务实现类
 * @Author:zhimingw
 * @Version 1.0
 * @since 2021/5/31 12:44
 */
@Service("adminService")
public class AdminServiceImpl extends BaseService implements AdminService {
    /**
    * @Description: 查询单条数据
    * @Param: [id]
    * @return: top.zhimingw.pojo.Admin
    * @Author: zhimingw
    * @Date: 2021/5/31
    */
    @Override
    public Admin queryById(Integer id) {
        Admin admin = null;
        if(redisService.exists(AdminKey.getById,String.valueOf(id))){
            admin = redisService.get(AdminKey.getById,String.valueOf(id),Admin.class);
        }else{
            admin = adminMapper.queryById(id);
            redisService.set(AdminKey.getById,String.valueOf(id),admin,60*60*24);
        }
        return admin;
    }

    /**
    * @Description: 修改数据，哪个属性不为空就修改哪个属性
    * @Param: [admin]
    * @return: boolean
    * @Author: zhimingw
    * @Date: 2021/5/31
    */
    @Override
    public boolean update(Admin admin) {
        if(adminMapper.update(admin)==1){
            return true;
        }
        return false;
    }
}
